capture log close
cd "C:\Research\Legal Services Corporation\"

log using "main_and_subgroup_results.txt", text replace

use "acs_small2008.dta", clear
  
foreach year in "09" "10" "11" "12" "13" "14" "15" "16" "17" {
  append using "acs_small20`year'.dta"
}

drop if cit==5 | mil==1


recode mig (1=0) (2 3=1), gen(moved)

gen rent=ten==3 if ten!=.

gen treat=povpip<125 & rent if povpip!=.

gen clustervar=povpip*10+rent

sum move if (povpip>=75 & povpip<=175) & rent==1

reghdfe move treat if (povpip>=75 & povpip<=175), absorb(rent povpip) cluster(clustervar)

recode hisp (1=0) (2/24=1), gen(hispanic)
gen racecat=rac1p*10+hispanic

replace eng=0 if eng==.
gen english=eng==1 | eng==2 | eng==0

replace lanx=0 if lanx==.
replace schl=0 if schl==.
replace schg=0 if schg==.
replace dis=0 if dis==.

local covs="rent povpip agep racecat sex mar eng lanx schl schg dis puma st#year"

reghdfe move treat if (povpip>=75 & povpip<=175), absorb(`covs') cluster(clustervar)

reghdfe move treat if (povpip>=75 & povpip<=175) & rac1p==1 & hispanic==0, absorb(`covs') cluster(clustervar)
reghdfe move treat if (povpip>=75 & povpip<=175) & rac1p==2 & hispanic==0, absorb(`covs') cluster(clustervar)
reghdfe move treat if (povpip>=75 & povpip<=175) & rac1p==6 & hispanic==0, absorb(`covs') cluster(clustervar)
reghdfe move treat if (povpip>=75 & povpip<=175) & hispanic, absorb(`covs') cluster(clustervar)

reghdfe move treat if (povpip>=75 & povpip<=175) & sex==1, absorb(`covs') cluster(clustervar)
reghdfe move treat if (povpip>=75 & povpip<=175) & sex==2, absorb(`covs') cluster(clustervar)

reghdfe move treat if (povpip>=75 & povpip<=175) & agep>=18 & agep<30, absorb(`covs') cluster(clustervar)
reghdfe move treat if (povpip>=75 & povpip<=175) & agep>=30 & agep<65, absorb(`covs') cluster(clustervar)
reghdfe move treat if (povpip>=75 & povpip<=175) & agep>=65, absorb(`covs') cluster(clustervar)

reghdfe move treat if (povpip>=75 & povpip<=175) & english==1, absorb(`covs') cluster(clustervar)
reghdfe move treat if (povpip>=75 & povpip<=175) & english==0, absorb(`covs') cluster(clustervar)

reghdfe move treat if (povpip>=75 & povpip<=175) & schl>=1 & schl<=15, absorb(`covs') cluster(clustervar)
reghdfe move treat if (povpip>=75 & povpip<=175) & schl>=16 & schl<=17, absorb(`covs') cluster(clustervar)
reghdfe move treat if (povpip>=75 & povpip<=175) & schl>=18 & schl<=24, absorb(`covs') cluster(clustervar)


drop region
recode st (9 23 25 33 44 50 34 36 42=1) (17 18 26 39 55 19 20 27 29 31 38 46=2) (10 11 12 13 24 37 45 51 54 01 21 28 47 5 22 40 48=3) (4 8 16 30 32 35 49 56 2 6 15 41 53=4) (nonmissing=.), gen(region)

forvalues i=1(1)4 {
  reghdfe move treat if (povpip>=75 & povpip<=175) & region==`i', absorb(`covs') cluster(clustervar)
}

bysort st year: egen pct25=pctile(rntp), p(25)
gen low_rent=rntp<=pct25

log close

